package com.zjk.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zjk.Result;
import com.zjk.category.CategoryBrandRelationEntity;
import com.zjk.mapper.CategoryBrandRelationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: gfk
 * @create: 2022/10/20
 * @Description:
 * @FileName: CategoryBrandRelationService
 * @History:
 * @自定义内容：
 */
@Service
public class CategoryBrandRelationService {

    @Autowired
    CategoryBrandRelationMapper relationMapper;

    public Result save(CategoryBrandRelationEntity relationEntity){
        if (relationEntity!=null){
            relationMapper.updateById(relationEntity);
            return Result.SUCCESS();
        }else {
            relationMapper.insert(relationEntity);
            return Result.SUCCESS();
        }
    }

    public Result deleteById(Long id){
        relationMapper.deleteById(id);
        return Result.SUCCESS();
    }

    public List<CategoryBrandRelationEntity> findCategoryBrandRelationByBrandId(Long brandId){
        QueryWrapper<CategoryBrandRelationEntity> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(CategoryBrandRelationEntity::getBrandId,brandId);
        List<CategoryBrandRelationEntity> list = relationMapper.selectList(wrapper);
        return list;
    }

    public List<CategoryBrandRelationEntity> findCategoryBrandRelationByCatId(Long categoryId){
        QueryWrapper<CategoryBrandRelationEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(CategoryBrandRelationEntity::getCatelogId,categoryId);
        List<CategoryBrandRelationEntity> categoryBrandRelationEntities = relationMapper.selectList(queryWrapper);

        return categoryBrandRelationEntities;
    }
}

